/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: ChainClient
 * Author:   zhouheng
 * Date:     2019/5/1 23:09
 * Description: 责任链模式客户端
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhouh.patterns.com.zhouh.action.chain;

import com.zhouh.patterns.com.zhouh.action.template.CashShoppingCart;
import com.zhouh.patterns.com.zhouh.action.template.ShoppingCart;
import com.zhouh.patterns.com.zhouh.create.factory.factoryMethod.AppleFactory;
import com.zhouh.patterns.com.zhouh.create.factory.factoryMethod.BananaFactory;
import com.zhouh.patterns.com.zhouh.create.factory.factoryMethod.OrangeFactory;
import com.zhouh.patterns.com.zhouh.entity.Fruit;

import java.util.ArrayList;
import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈责任链模式客户端〉
 *
 * @author zhouheng
 * @create 2019/5/1
 * @since 1.0.0
 */
public class ChainClient {
    public static MultyDiscount multyDiscount = new FullMultyDiscount(null);

    static {
        multyDiscount = new HolidayMultyDiscount(multyDiscount);
        multyDiscount = new NewerMultyDiscount(multyDiscount);
        multyDiscount = new SecondMultyDiscount(multyDiscount);
    }

    public static void main(String[] args){
//        int money = 300;
//        System.out.println("打折前应付价："+ money);
//        int discountMoney = multyDiscount.calculate(money);
//        System.out.println("折后价：" + discountMoney);

        List<Fruit> fruits = new ArrayList<>();
        fruits.add(new AppleFactory().getFruit());
        fruits.add(new OrangeFactory().getFruit());
        fruits.add(new BananaFactory().getFruit());

        ShoppingCart shoppingCart = new CashShoppingCart(fruits);
        shoppingCart.setDiscount(multyDiscount);
        shoppingCart.submitOrder();

    }

}